/**
 * 
 */
package com.qiyou.dao.proxy;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.qiyou.dao.IBlogCommentDao;
import com.qiyou.dao.impl.BlogCommentDaoImpl;
import com.qiyou.db.IDatabase;
import com.qiyou.entity.BlogComment;
import com.qiyou.util.DBUtil;

/**
 * 博客评论数据信息操作代理
 * 
 * @author 赛艳志
 * 
 */
public class BlogCommentDaoProxy implements IBlogCommentDao {
    private Connection conn = null;
    private IBlogCommentDao dao = null;

    public BlogCommentDaoProxy(IDatabase database) {
        this.conn = database.getConnection();
        this.dao = new BlogCommentDaoImpl(conn);
    }

    @Override
    public boolean doCreate(BlogComment blogComment) throws SQLException {
        if (null != blogComment) {
            try {
                return dao.doCreate(blogComment);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public boolean doUpdate(BlogComment blogComment) throws SQLException {
        if (null != blogComment) {
            try {
                return dao.doUpdate(blogComment);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public boolean doDelete(long blogCommentID) throws SQLException {
        if (blogCommentID > 0) {
            try {
                return dao.doDelete(blogCommentID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return false;
    }

    @Override
    public BlogComment getBlogComment(long blogCommentID) throws SQLException {
        if (blogCommentID > 0) {
            try {
                return dao.getBlogComment(blogCommentID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

    @Override
    public List<BlogComment> getBlogComments(String userID) throws SQLException {
        if (null != userID) {
            try {
                return dao.getBlogComments(userID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

    @Override
    public List<BlogComment> getBlogComments(long blogID) throws SQLException {
        if (blogID > 0) {
            try {
                return dao.getBlogComments(blogID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

    @Override
    public List<BlogComment> getBlogComments(Object... params)
            throws SQLException {
        if (null != params) {
            try {
                return dao.getBlogComments(params);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return null;
    }

}
